package org.jeecg.modules.xindian.reconciliation.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.poi.ss.formula.functions.T;
import org.jeecg.modules.xindian.reconciliation.controller.rsp.MangeOptions;
import org.jeecg.modules.xindian.reconciliation.entity.Salesman;
import org.jeecg.modules.xindian.reconciliation.enums.DeleteFlagEnum;
import org.jeecg.modules.xindian.reconciliation.mapper.SalesmanMapper;
import org.jeecg.modules.xindian.reconciliation.service.ISalesmanManagerRateService;
import org.jeecg.modules.xindian.reconciliation.service.ISalesmanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 业务员信息表
 * @Author: jeecg-boot
 * @Date:   2024-04-11
 * @Version: V1.0
 */
@Service
public class SalesmanServiceImpl extends ServiceImpl<SalesmanMapper, Salesman> implements ISalesmanService {
    @Autowired
    private ISalesmanManagerRateService managerRateService;
    @Autowired
    private TransactionTemplate transactionTemplate;
    @Override
    public IPage<Salesman> pageQuery(Page page) {
        return getBaseMapper().pageQuery(page);
    }

    @Override
    public void deleteSalesman(String id) {
        Assert.notNull(id,"id不能为空");
        transactionTemplate.execute(status -> {
            removeById(id);
            managerRateService.deleteSalesman(id);
            return null;
        });

    }

    @Override
    public List<MangeOptions> selectOption() {
        List<Salesman>   salesmanList = lambdaQuery().eq(Salesman::getDeleteFlag,DeleteFlagEnum.N).list();
       return salesmanList.stream().map(one->{
            MangeOptions mangeOptions = new MangeOptions();
            mangeOptions.setTag(one.getName());
            mangeOptions.setId(one.getId());
            return mangeOptions;
        }).collect(Collectors.toList());
    }
}
